package model.item;

import model.entity.BasicEntity;
import model.skill.Projectile;
import model.skill.ProjectileInformation;
import utilities.*;

public class TakeableItem extends ProjectileItem implements Archiveable {
	
	private int price;
	
	public TakeableItem(String name)
	{
		super(name);
		setPrice(0);
	}
	
	public TakeableItem(String name, Projectile projectile, int price)
	{
		super(name, projectile);
		this.setPrice(price);
	}
	
	public TakeableItem() {
		// TODO Auto-generated constructor stub
	}

	public void use(BasicEntity entity)
	{
		ProjectileInformation projectileInfo = new ProjectileInformation(entity.getLocation(), entity.getDirection());
		super.getProjectile().propagate(projectileInfo);
		entity.removeItem(this);
	}
	
	public void touch(BasicEntity entity)
	{
		entity.getInventory().addItem(this);
	}

	/**
	 * @param price the price to set
	 */
	public void setPrice(int price) {
		this.price = price;
	}

	/**
	 * @return the price
	 */
	public int getPrice() {
		return price;
	}
	
	public Archive save() {
		Archive archive = super.save();
		
		archive.putAttribute("price", Integer.toString(this.price));
		
		return archive;
	}
	
	public void load(Archive archive) {
		super.load(archive);
		
		this.price = Integer.parseInt(archive.getAttribute("price"));
	}
}
